// pages/user/user.js
const app = getApp()
Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 页面的初始数据
   */
  data: {
    user: false,
    userinfo: "",
    modalName:false
  },
  attached(){
    if (app.globalData.userInfo){
      this.setData({
        user:true,
        userinfo: app.globalData.userInfo
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  methods:{
    bindGetUserInfo(res) {
      if (res.detail.userInfo) {
        // let userinfo = JSON.parse(res.detail.rawData)
        app.globalData.userInfo = res.detail.userInfo
        let that = this;
        that.setData({
          user:true,
          userinfo: res.detail.userInfo
        })
        console.log("点击了同意授权");
        wx.login({
          success: function (res) {
            console.log("code",res);
          }
        })
      } else {
        console.log("点击了拒绝授权");
      }
    },
    showModal(){
      let that = this;
      that.setData({
        modalName: "bottomModal"
      })
    },
    hideModal(){
      let that = this;
      that.setData({
        modalName: false
      })
    },
    // 手机
    phone(){
      wx.makePhoneCall({
        phoneNumber: '18850059236',
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
})